package fzdy.core.bean;

/**
 * Created by Administrator on 2017/3/27 0027.
 */
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.HashMap;

public class FileOutput {
    protected File file;
    protected String filename;
    protected InputStream inputStream;
    protected String contentType;
    private static HashMap<String, String> contentTypeMap = new HashMap();

    public FileOutput(String filename, InputStream inputStream) {
        this.contentType = "application/octet-stream";
        this.filename = filename;
        this.inputStream = inputStream;
    }

    public FileOutput(File file, String filename) {
        this.contentType = "application/octet-stream";
        this.file = file;
        this.filename = filename;
        int lastIndexOf = filename.lastIndexOf(".");
        String substring = filename.substring(lastIndexOf);

        try {
            this.inputStream = new FileInputStream(file);
        } catch (FileNotFoundException var6) {
            var6.printStackTrace();
        }

        String s = (String)contentTypeMap.get(substring);
        if(s != null) {
            this.contentType = s;
        }

    }

    public FileOutput(File file) {
        this(file, file.getName());
    }

    public FileOutput(String path, String filename) {
        this(new File(path), filename);
    }

    public FileOutput(String path) {
        this(new File(path));
    }

    public File getFile() {
        return this.file;
    }

    public InputStream getInputStream() {
        return this.inputStream;
    }

    public String getFilename() {
        return this.filename;
    }

    public String getContentType() {
        return this.contentType;
    }

    public void setContentType(String contentType) {
        this.contentType = contentType;
    }

    static {
        contentTypeMap.put(".png", "image/png");
        contentTypeMap.put(".ico", "image/x-ico");
        contentTypeMap.put(".jpe", "image/jpeg");
        contentTypeMap.put(".jfif", "image/jpeg");
        contentTypeMap.put(".jpg", "image/jpeg");
        contentTypeMap.put(".jpeg", "image/jpeg");
        contentTypeMap.put(".wbmp", "image/vnd.wap.wbmp");
    }
}
